There are dormitories in Berland State University, they are numbered with integers from to . Each dormitory consists of rooms, there are rooms in -th dormitory. The rooms in -th dormitory are numbered from to .
A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all dormitories is written on an envelope. In this case, assume that all the rooms are numbered from to and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.
For example, in case , and an envelope can have any integer from to written on it. If the number is written on an envelope, it means that the letter should be delivered to the room number of the second dormitory.
For each of letters by the room number among all dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Input
The first line contains two integers and — the number of dormitories and the number of letters.
The second line contains a sequence , where equals to the number of rooms in the -th dormitory. The third line contains a sequence , where equals to the room number (among all rooms of all dormitories) for the -th letter. All are given in increasing order.
Output
Print lines. For each letter print two integers and — the dormitory number and the room number in this dormitory to deliver the letter.
1 | Examples |
解析:
题意: 查询m个数分别在一个有n个元素的递增序列中的相对位置。
两种解法:
暴力解法为两层嵌套循环,时间复杂度为O(m×n);
二分法查找,时间复杂度为O(m×log2n)
1 |
|
out put
1 | 1 1 |